package com.fs.jzzn.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.fs.jzzn.pojo.Flow;
/**
 * @author TiddlerCJ
 */
public interface FlowRepository extends JpaRepository<Flow,String>, JpaSpecificationExecutor<Flow>{
	/**
	 * @param parentId
	 * @return
	 */
	List<Flow> findByParentIdOrderByFlowOrderAsc(String parentId);
	
	/**
	 * 查询第一流程节点
	 * @param flowTemplateId
	 * @return
	 */
	@Query( value="select * from p_flow f where f.parent_id = ?1 ORDER BY flow_order asc LIMIT 0,1" ,nativeQuery=true)
	Flow getFirstNode(String flowTemplateId);
	
	/**
	 * 查询下一流程节点
	 * @desc 当下一个流程节点为null时代表流程结束
	 * @param flowTemplateId
	 * @param currentNodeId
	 * @return
	 */
	/*@Query(value = "select * from p_flow f where f.parent_id = ?1 AND f.id <> ?2 ORDER BY flow_order asc LIMIT 0,1 ",nativeQuery=true)
	Flow getNextNode(String flowTemplateId,String currentNodeId);*/
}
